<?php
require 'db_conn.php';
$id=isset($_GET['id']) ?$_GET['id']: 0;//判断地址栏有没有ID的值，如果有
if(empty($_POST))
{
    $sql="select*from t_message where id='$id'";


 $result=$db->query($sql);
 
 //处理结果集  结果集是多行
 
 $row=$result->fetch_assoc();
 
require 'edit_html.php';
}
 else {
    $username=$_POST["username"];
$sex=$_POST["sex"];
$message=$_POST["message"];
$imgurl=$_POST["imgurl"];
$sql="update t_message set username='$username',sex='$sex',message='$message',imgurl='$imgurl' where id=$id";

 $result=$db->query($sql);//
 
 if ($result)
 {
     echo "<script language='javascript' type='text/javascript'>";
     echo "alert('修改成功');";
     echo "window.location.href='index.php';";
     echo "</script>";
 }
 else {
     echo "<script language='javascript' type='text/javascript'>";
     echo "alert('修改失败！');";
     echo "window.location.href='index.php';";
     echo "</script>";
        }
}


